package com.ljf.config.infra.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.infra.repository.impl.BasisRepositoryImpl;
import com.ljf.common.utils.CollectionUtil;
import com.ljf.common.utils.EnumUtil;
import com.ljf.config.domain.repository.ConfigDatRecordSymbolRepository;
import com.ljf.config.dto.query.ConfigDatRecordSymbolQuery;
import com.ljf.config.enums.ConfigDatRecordSymbolTypeEnum;
import com.ljf.config.infra.mapper.ConfigDatRecordSymbolMapper;
import com.ljf.config.model.ConfigDatRecordSymbol;
import com.ljf.config.vo.ConfigDatRecordSymbolVO;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 记录标签配置  数据访问接口实现
 *
 * @author LJF
 * @since 2025-02-01
 */
@Component
public class ConfigDatRecordSymbolRepositoryImpl extends BasisRepositoryImpl<ConfigDatRecordSymbolMapper, ConfigDatRecordSymbol, ConfigDatRecordSymbolQuery, ConfigDatRecordSymbolVO> implements ConfigDatRecordSymbolRepository {

    @Override
    protected QueryWrapper<ConfigDatRecordSymbol> fillWrapper(ConfigDatRecordSymbolQuery query, boolean sort) throws ServiceException {
        QueryWrapper<ConfigDatRecordSymbol> wrapper = super.fillWrapper(query, sort);
        if (CollectionUtil.isNotEmpty(query.getCodeList())) {
            wrapper.in(ConfigDatRecordSymbol.COL_CODE, query.getCodeList());
        }
        return wrapper;
    }

    @Override
    protected void fillInfo(List<ConfigDatRecordSymbolVO> resultList) throws ServiceException {
        super.fillInfo(resultList);
        if (CollectionUtil.isNotEmpty(resultList)) {
            Map<Integer, String> typeMap = EnumUtil.getCodeToNameMap(ConfigDatRecordSymbolTypeEnum.values());
            for (ConfigDatRecordSymbolVO result : resultList) {
                result.setTypeName(typeMap.getOrDefault(result.getType(), ""));
            }
        }
    }

}
